package com.wuliu.driver.controller;

import com.wuliu.driver.pojo.Orders;
import com.wuliu.driver.service.OrdersService;
import com.wuliu.driver.util.Result;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/orders")
public class OrdersController {
    @Autowired
    private OrdersService ordersService;
    @Autowired
    private RabbitTemplate rabbitTemplate;
    //查询该用户的订单
    @GetMapping("/select/{did}")
    public Result select(@PathVariable Integer did){
        return ordersService.select(did);
    }
    //添加订单
    @PostMapping("/add")
    public Result add(@RequestBody Map map){
        System.out.println(map);
        return ordersService.add(map);
    }
    //修改订单状态
    @GetMapping("/upd/{id}/{status}")
    public Result cancel(@PathVariable Integer id,@PathVariable Integer status){
        return ordersService.upd(id,status);
    }

    //打卡
    @PostMapping("/ka")
    public Result ka(@RequestBody Map map){
        return ordersService.ka(map);
    }

    //上传空车重量图片，装车重量图片，装货吨数
    @PostMapping("/upload")
    public Result upload(@RequestBody Orders orders){
        return ordersService.upload(orders);
    }
    //修改订单，卸车时候的操作
    @PostMapping("/upddd")
    public Result upd(@RequestBody Orders orders){
        System.out.println(orders);
        return ordersService.upd(orders);
    }

    //查询用户的订单
    @GetMapping("/selectOrder/{id}")
    public Result selectOrder(@PathVariable Integer id){
        return ordersService.selectOrder(id);
    }

    //订单完成执行的业务
    @GetMapping("/finish/{id}")
    public Result finish(@PathVariable Integer id){

        return ordersService.finish(id);
    }

    @RequestMapping("/cs")
    public String cs(){
        rabbitTemplate.convertAndSend("orders_finish",15);
        return "发送成功";
    }

    //查询该用户的所有订单
    @PostMapping("/selectAll")
    public Result selectAll(@RequestBody Orders orders){
        System.out.println(orders);
        return ordersService.selectAll(orders);
    }

}
